﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

public class FileUtils
{
    //获取这个文件夹下面的所有文件夹
    public static List<string> getAllFolder(string path, bool addCurrent = true)
    {
        List<string> pathLst = new List<string>();
        if (addCurrent)
        {
            pathLst.Add(path);
        }
        getAllPath(path, ref pathLst);
        return pathLst;
    }
    private static void getAllPath(string path, ref List<string> pathLst)
    {
        string[] arr = Directory.GetDirectories(path);
        for (int i = 0; i < arr.Length; i++)
        {
            getAllPath(arr[i], ref pathLst);
        }
        string[] nometa = arr.Where(p => !p.EndsWith(".meta")).ToArray();
        pathLst.AddRange(nometa);
    }

    // 获取这个文件夹下面所有的文件
    public static string[] getAllFiles(string flolder)
    {
        string[] files = Directory.GetFiles(flolder);
        return files.Where(p => !p.EndsWith(".meta")).ToArray();
    }

    //获取文件夹里面的文件 不递归找
    public static List<string> getFiles(string flolder, string[] suff)
    {
        string[] files = Directory.GetFiles(flolder);
        List<string> result = new List<string>();
        for (int i = 0; i < files.Length; i++)
        {
            string f = files[i];
            for (int k = 0; k < suff.Length; k++)
            {
                if (Path.GetExtension(f) == suff[k])
                {
                    result.Add(f);
                    continue;
                }
            }
        }
        return result;
    }
    //获取文件夹里面的文件 递归找
    public static List<string> getAllFiles(string flolder, string[] suff)
    {
        List<string> allflolder = getAllFolder(flolder, true);
        List<string> result = new List<string>();
        for (int p = 0; p < allflolder.Count; p++)
        {
            string[] files = Directory.GetFiles(allflolder[p]);
            for (int i = 0; i < files.Length; i++)
            {
                string f = files[i];
                for (int k = 0; k < suff.Length; k++)
                {
                    if (Path.GetExtension(f) == suff[k])
                    {
                        result.Add(f);
                        continue;
                    }
                }
            }
        }
        return result;
    }

}

